/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.iitbd.hxcalc;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.supercsv.io.CsvListWriter;
import org.supercsv.prefs.CsvPreference;

/**
 *
 * @author Prasun Kanti Howlader
 */
public class CSVReaderWriter {

    CsvPreference preference = null;
    File filename = null;
    char seperator;
    CsvListWriter writer = null;

    public CSVReaderWriter() {
    }

    public CSVReaderWriter(File filename, char ch) {
        this.filename = filename;
        seperator = ch;
        preference = new CsvPreference('"', seperator, "\n");
        try {
            writer = new CsvListWriter(new FileWriter(filename), preference);
        } catch (IOException ex) {
            Logger.getLogger(CSVReaderWriter.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void writeCSV(List<String> values) {
        try {


            writer.write(values);
        } catch (Exception e) {
        }

    }

    public void writeCSV() {
        try {

            writer.writeHeader("Comment");
            writer.writeHeader("Comment");
            writer.writeHeader("Comment");

        } catch (Exception e) {
        }

    }

    public void close() {
        try {
            writer.close();
        } catch (IOException io) {
        }
    }

    public void setCSVPreference(char seperator) {
        preference = new CsvPreference('"', seperator, "\n");
    }
}
